package com.lifang.framework.beans.factory.support;

import cn.hutool.core.util.ReflectUtil;
import com.lifang.framework.beans.BeansException;
import com.lifang.framework.beans.factory.config.InstantiationStrategy;

import java.lang.reflect.Constructor;

public class JdkInstantiationStrategy implements InstantiationStrategy {
    @Override
    public Object instantiation(BeanDefinition beanDefinition, String beanName, Constructor<?> constructor, Object[] args) {
        try {
            ReflectUtil.setAccessible(constructor);
            return constructor.newInstance(args);
        } catch (Exception ex) {
            throw new BeansException(beanName + " initialization error");
        }
    }
}
